package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.POJO.CheckGroup;
import com.itheima.health.POJO.Setmeal;
import com.itheima.health.dao.SetmealDao;
import com.itheima.health.exception.CustomerException;
import com.itheima.health.service.SetmealService;
import com.itheima.health.service.Setmeal_CheckgroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealDao, Setmeal> implements SetmealService {
    @Autowired
    private Setmeal_CheckgroupService scService;

    /**
     * @description 套餐添加方法
     * @date 2021/11/28 10:48
     * @param setmeal:
     */
    @Override
    public void addSetmeal(Setmeal setmeal) {
        //0.查找是否存在同名或同code的套餐
        LambdaQueryWrapper<Setmeal> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Setmeal::getCode,setmeal.getCode())
                .or().
                eq(Setmeal::getName,setmeal.getName());
        Setmeal one = getOne(wrapper);
        if(one!=null){
            throw new CustomerException("套餐已存在");
        }
        //1.套餐表添加套餐
        save(setmeal);
        //2.中间表添加套餐表和检查组关联
        List<CheckGroup> checkGroups = setmeal.getCheckGroups();

    }
}
